package com.wolfword.crawler.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wolfword.common.util.object.StringUtil;
import com.wolfword.crawler.server.service.AnalyzedInfoListService;

/**
 * 网页解析内容表
 * 
 * @author Server Zhang
 * @date 2018-01-11 10:54:52
 */
@RestController
@RequestMapping("/analysis/info")
@Api(value="/analysis/info",description="网页解析内容表")
public class AnalyzedInfoListController {
	
	private final Logger logger = LoggerFactory.getLogger(AnalyzedInfoListController.class);
	
	@Autowired
	private AnalyzedInfoListService analyzedInfoListService;
	
	/**
	 * 批量插入数据
	 * @param request
	 * @param infoJson
	 * @author ServerZhang
	 * @date 2018年1月16日
	 */
	@ApiOperation("批量插入数据")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "infoJson", value = "网页解析出的信息列表json", paramType = "query", dataType = "string", required = true)
    })
	@PostMapping("batchInsert")
    public void batchInsert(HttpServletRequest request,
    		String infoJson){
    	
    	if (StringUtil.isEmpty(infoJson)) {
    		return;
    	}
    	//检查字符串是否合法
    	if (!infoJson.startsWith("[") || !infoJson.endsWith("]")) {
    		return;
		}
    	
    	analyzedInfoListService.insertInfo(infoJson);
    }
}
